#ifndef __YMODEM_H
#define __YMODEM_H
#include "type.h"
#include "flash.h"
#define YMODEM_SOH		0x01
#define YMODEM_STX		0x02
#define YMODEM_EOT		0x04
#define YMODEM_ACK		0x06
#define YMODEM_NAK		0x15
#define YMODEM_CA		0x18
#define YMODEM_C		0x43

#define ApplicationAddress 0x08004000

#define ERASE_SECTORS	((0x8010000 - ApplicationAddress) / FLASH_SECTOR_SIZE) 

typedef enum {
	UPDATE_SUCCESS = 0,
	WAIT_ENTER_SYSTEM,
	BUSY,
	START_PROGRAM,
	UPDATE_PROGRAM,
	SET_PARAMETER
} ProcessStatus;

typedef void (*YModem_Callback)(ProcessStatus);

typedef struct {
	ProcessStatus process;
	uint8_t status;
	uint8_t id;
	uint32_t addr;
	uint32_t filesize;
	char filename[32];
	YModem_Callback cb;
} YModem;

void Set_YModem_Status(ProcessStatus process);
ProcessStatus Get_YModem_Status(void);
void YModem_Start(YModem_Callback cb);
void YModem_Recv(Buffer *p);
#endif
